<?php

class Default_Model_Tourcategory extends Zend_Db_Table_Abstract
{
    protected $_db;

	public function __construct()
	{
		$this->_db = Zend_Registry::get('db');
	}

    public function listItem($locale)
    {
        $sql = $this->_db->select()
                        ->from('tour_category AS c')
                        ->join('tour_category_language AS cl', 'cl.category_id = c.id', array('cl.name'))
                        ->join('language AS l', 'l.id = cl.language_id', null)
                        ->where('c.status = ?', 1)
                        ->where('l.locale = ?', $locale)
                        ->order('c.id ASC');
        $result = $this->_db->fetchAll($sql);
        return $result;
    }

	public function getCategoryName($id, $locale)
    {
        $sql = $this->_db->select()
                        ->from('tour_category_language AS cl', array('name'))
                        ->join('language AS l', 'l.id = cl.language_id', null)
                        ->where('cl.category_id = ?', $id)
                        ->where('l.locale = ?', $locale);
        $result = $this->_db->fetchOne($sql);
        return $result;
    }
}
